# -*- coding: utf-8 -*-
#coding = utf-8

import sys

base = [str(x) for x in range(10)] + [ chr(x) for x in range(ord('A'), ord('A') + 6)]

def hex2dec(hex_num):
	return ord(hex_num)

def dec2hex(num,l=2):
	num = int(num)
	mid = []
	while True:
		if num == 0 : break
		num, rem = divmod(num, 16)
		mid.append(base[rem])

	result = ''.join([str(x) for x in mid[::-1]])

	while len(result) < l:
		result = ''.join(['0',result])

	result_list = []

	result = list(result)
	for i in range(0,len(result),2):
		v = ''.join(result[i:i+2])
		v = chr(int(v,16))
		result_list.append(v)

	return result_list[::-1]


def dec2bin(num):
	mid = []
	result = ['0','0','0','0','0','0','0','0']
	while True:
		if num == 0: break
		num, rem = divmod(num, 2)
		mid.append(base[rem])

	for i in range(len(mid)):
		result[i] = str(mid[i])
	return result[::-1]

def hex2bin(num):
	return dec2bin(hex2dec(num))

def bin2dec(string_num):
	return str(int(string_num, 2))

def bin2hex(string_num):
	return dec2hex(bin2dec(string_num))

def get_string(byte_list):
	text = ''
	for s in byte_list:
		i = ord(s)
		text = text + chr(i)

	return text

def hex2dec_minute(num):
	num = int(num)
	if num == 0:
		return 0
	mid = []
	while True:
		if num == 0 : break
		num, rem = divmod(num, 16)
		mid.append(base[rem])

	result = ''.join([str(x) for x in mid[::-1]])

	return result

def string2hex(string):
	a = []

	if string == 'reset':
		a = ['\xff','\xff','\xff','\xff','\xff','\xff']
		return a

	for c in string:
		i = ord(c)
		h = dec2hex(i)
		a.append(h[0])

	return a
